package com.rybbaby.tss.core.redis;

import com.rybbaby.tss.core.utils.SpringApplicationContextUtil;
import org.apache.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import redis.clients.jedis.Jedis;
import redis.clients.jedis.JedisPool;

/**
 * @description jedis 生成工厂
 * 
 * @author 谢进伟
 * 
 * @createDate 2016年12月7日 下午3:50:07
 */
class RedisFactory {
	
	private static Logger log = Logger.getLogger(RedisFactory.class);
	
	@Autowired
	private static JedisPool jedisPool;

	static {
		jedisPool= SpringApplicationContextUtil.getBean(JedisPool.class);
	}
	
	public static Jedis getJedis() {
		Jedis shardJedis = null;
		try {
			shardJedis = jedisPool.getResource();
			return shardJedis;
		} catch (Exception e) {
			log.error("[JedisDS] getRedisClent error:" + e.getMessage());
			if(null != shardJedis)
				shardJedis.close();
		}
		return null;
	}
	
	public static void close(Jedis jedis) {
		jedis.close();
	}
}
